package com.snbc.Exception;

import java.math.BigDecimal;

/**
 * @Classname Account
 * @Description Account类： 银行账号
 * 属性： balance 余额
 * 方法： getBalance() 获取余额
 * 方法： deposit() 存钱
 * 方法： withdraw() 取钱
 * @Date 2019/9/15 22:12
 * @Created by Acer
 */
public class Account {

    public BigDecimal account;//账户上的余额

    public BigDecimal getAccount() {
        return account;
    }

    public void setAccount(BigDecimal account) {
        this.account = account;
    }

    public Account(BigDecimal account1) {
        this.account = account1;
        //System.out.println("账户余额：" + account1);
    }

    //获取余额
    public BigDecimal getBalance() {
        return account;
    }

    //存钱
    public void deposit(BigDecimal money) {
        account = account.add(money);
        System.out.println("存款金额为：" + money);
        System.out.println("存款成功，余额为：" + account);
    }

    //取钱
    public void withdraw(BigDecimal money) throws OverdraftException {

        if (money.compareTo(account) == 1) {
            System.out.println();
            throw new OverdraftException("余额不足：" + account);
        } else {
            account = account.subtract(money);
            System.out.println("取款金额为：" + money);
            System.out.println("账户余额为：" + account);

        }
    }
}
